<script>
	export default {
		onLaunch: function() {
			this.$store.commit('initUser');
		},
		onShow: function() {
			uni.connectSocket({
				url: 'wss://tzdj.1qit.com:9502/',
				header: {
					'content-type': 'application/json'
				},
				method: 'GET',
				complete: (res) => {
					console.log(res)
				}
			});
			uni.onSocketOpen(function(res) {
				console.log('WebSocket连接已打开');
				let data = JSON.stringify({type:'open',token:uni.getStorageSync("token")}) 
				uni.sendSocketMessage({
					data:data,
					header: {
						'content-type': 'application/json'
					}
				})
			});
			uni.onSocketError(function(res) {
				console.log('WebSocket连接打开失败，请检查！');
			});
			uni.onSocketMessage(function(res) {
				console.log('收到服务器内容：' + res);
				setTimeout(() => {
					uni.showModal({
						title: '提示',
						content: '您的订单已被司机接单，请点击查看',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: "/pages/carOwner/myOrder/index"
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}, 5000)
			});
		},
		onHide: function() {
			console.log('App Hide')
			uni.closeSocket()
		}
	}
</script>

<style>
	page {
		-webkit-overflow-scrolling: touch;
		word-break: break-all;
	}

	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
		display: none;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
</style>
<style lang="scss">
	@import 'uview-ui/theme.scss';
	@import "static/css_style/index.scss";
	@import "static/css_style/animate.min.css";
</style>
